package com.wwd.movie.login.domain.dto;

import com.wwd.movie.login.domain.entity.MovieUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

@Data
@AllArgsConstructor
public class LoginUser implements UserDetails {

    private MovieUser user;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 如果暂时不做权限，可以返回空集合
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !"1".equals(user.getStatus()); // status=1 表示禁用
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return !"1".equals(user.getStatus());
    }
}
